import App from './App'

// #ifndef VUE3
import Vue from 'vue'

Vue.config.productionTip = false
App.mpType = 'app'
import { tools } from './static/js/tools.js'
import store from '@/store/index'
// import { useLevel } from '@/utils/level'
import loading from '@/utils/loading'
//配置公共方法  防治多次点击
import noclick from 'api/noclick.js'

Vue.prototype.$noMultipleClicks = noclick.noMultipleClicks;
Vue.prototype.header = tools.header
Vue.prototype.show = tools.show
Vue.prototype.equal = tools.equal


// 引入自定义指令，用于显示指定的等级背景、
// uni-app不支持
// useLevel(Vue)
try {
  function isPromise(obj) {
    return (
      !!obj &&
      (typeof obj === 'object' || typeof obj === 'function') &&
      typeof obj.then === 'function'
    )
  }

  // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  uni.addInterceptor({
    returnValue(res) {
      if (!isPromise(res)) {
        return res
      }
      return new Promise((resolve, reject) => {
        res.then((res) => {
          if (res[0]) {
            reject(res[0])
          } else {
            resolve(res[1])
          }
        })
      })
    },
  })
} catch (error) {
}

Vue.use(loading)
const app = new Vue({
  ...App,
  store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'

export function createApp() {
  const app = createSSRApp(App)
  return {
    app,
  }
}

// #endif